package yxy.game.pm2.command.stairway;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.bean.PlayerBean;
import yxy.game.pm2.bean.ServerBean;
import yxy.game.pm2.bean.area.AreaBean;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.StairwayMessage;
import yxy.game.pm2.module.stairway.StairwayHandle;

/** 天梯争雄 天梯争雄 */
@MessageType(proto = Command.StairwayUI, classtype = StairwayMessage.StairwayUIRequest.class)
public class CMD_StairwayUI extends Command<StairwayMessage.StairwayUIRequest> {

	@Override
	public void execute(MessageSource messageSource, StairwayMessage.StairwayUIRequest request) {
		String playerCode = messageSource.getTag();

		StairwayMessage.StairwayUIResponse.Builder response = StairwayMessage.StairwayUIResponse.newBuilder();

		PlayerBean playerBean = PlayerBean.get(playerCode);
		ServerBean serverBean = ServerBean.get(playerBean.getServerId());
		AreaBean areaBean = AreaBean.get(serverBean.getAreaId());
		Result result = new StairwayHandle().stairway(areaBean.getGroupId(), playerCode, response);

		send(messageSource, response, result);
	}

	private void send(MessageSource messageSource, StairwayMessage.StairwayUIResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
}